<template>
  <div :class="['message-box',type]">
    <div class="inner">
      <header class="header">
        <h1 class="title">{{title}}</h1>
        <span class="close" @click="$messageBox.hide()">x</span>
      </header>
      <div class="content">{{content}}</div>
    </div>
  </div>
</template>

<script>
export default {
  name: "messageBox",
  props: {
    title: {
      type: String,
      default: "这是标题"
    },
    content: {
      type: String,
      default: "这是内容"
    },
    type: {
      type: String,
      default: "primary",
      validator(value) {
        //检查内容
        return ["primary", "success", "warn", "danger"].includes(value);
      }
    }
  }
};
</script>

<style lang="less" scoped>
body {
  margin: 0;
  padding: 0;
}
h1 {
  margin: 0;
  font-weight: normal;
}
.message-box {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  .inner {
    position: absolute;
    top: 100px;
    left: 50%;
    width: 500px;
    margin-left: -250px;
    background: #fff;
    box-shadow: 1px 3px 5px #ededed;
    border-radius: 5px;
    overflow: hidden;
    .header {
      height: 44px;
      padding: 0 10px;
      box-sizing: border-box;
      .title {
        float: left;
        font-size: 16px;
        line-height: 44px;
      }
      .close {
        float: right;
        cursor: pointer;
        font-size: 18px;
      }
    }
    .content {
      padding: 20px;
      box-sizing: border-box;
    }
  }
  &.primary {
    header {
      background: blue;
      color: #fff;
    }
  }
  &.success {
    header {
      background: green;
      color: #fff;
    }
  }
  &.warn {
    header {
      background: orange;
      color: #333;
    }
  }
  &.danger {
    header {
      background: red;
      color: #fff;
    }
  }
}
</style>